package com.blb.community.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.community.Annotation.Log;
import com.blb.community.entity.SysOperLog;
import com.blb.community.service.ISysOperLogService;
import com.blb.community.utils.EasyExcelUtil;
import com.blb.community.utils.ResponseResult;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author 帅帅
 * @since 2022-07-02
 */
@Api(tags = "操作日志管理模块")
@RestController
@RequestMapping("/sys-oper-log")
public class SysOperLogController {

    @Autowired
    ISysOperLogService iSysOperLogService;

    /**
     * 分页查询日志列表
     * @return
     */
//    @ApiOperation("查询日志")
//    @GetMapping("/operLogPage")
//    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
//    public ResponseResult<IPage<SysOperLog>> getAllOperLogPage(Long current){
//        IPage<SysOperLog> operLogPage = iSysOperLogService.getOperLogPage(current, 5L);
//        return ResponseResult.ok(operLogPage);
//    }


    /**
     * 删除日志
     * @param idList
     * @return
     */
    @Log(module = "删除日志",operationType =3,requestMethod = "DELETE")
    @ApiOperation("删除日志")
    @DeleteMapping("/deleteOperLog/{idList}")
    public ResponseResult<String> deleteOperLog(@PathVariable ArrayList<String> idList){
        iSysOperLogService.removeByIds(idList);
        return ResponseResult.ok("删除成功");
    }

    @ApiOperation("日志详情")
    @GetMapping("/operLogDetails/{id}")
    public ResponseResult<List<SysOperLog>> selectAllOperLog(@PathVariable Long id){
      return ResponseResult.ok(iSysOperLogService.selectOperLogDetails(id));
    }

    @ApiOperation("模糊查询")
    @GetMapping("/fuzzyOperLog")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    public ResponseResult<IPage<SysOperLog>> getFuzzyOperLog(Long current,String title, String operName, String businessType, String status, String beginTime, String endTime){
        return ResponseResult.ok(iSysOperLogService.getFuzzyOperLog(current,5L,title,operName,businessType,status,beginTime,endTime));
    }

    @ApiOperation("表格导出")
    @PostMapping("/excel")
    public void downloadExcel(@RequestBody List<SysOperLog> list, HttpServletResponse response){
        EasyExcelUtil.write(list,SysOperLog.class,response);
    }

}
